package com.ar.customview;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

import com.actionbarsherlock.internal.widget.IcsAdapterView.OnItemSelectedListener;
import com.actionbarsherlock.internal.widget.IcsSpinner;

/**
 * The Class AbExamTitle.
 * @author anh
 */
public class AbExamTitle extends LinearLayout {
	
	/** The title. */
	public String title;
	
	/** The tv title. */
	private TextView tvTitle;
	
	/** The ics sp index. */
	private IcsSpinner icsSpIndex;

	
	/**
	 * Instantiates a new ab exam title.
	 *
	 * @param context the context
	 * @param adapter the adapter
	 * @param title the title
	 */
	public AbExamTitle(Context context, SpinnerAdapter adapter, String title) {
		super(context);
		this.title = title;
		
		this.setOrientation(VERTICAL);
		this.setPadding(10, 0, 0, 0);
		
		tvTitle = new TextView(context);
		//tvTitle.setTextAppearance(context, R.style.TextAppearance_Sherlock_Widget_ActionBar_Title);
		
		tvTitle.setText(title);
		tvTitle.setTextSize(15);
		tvTitle.setPadding(2, 0, 0, 0);
		//tvTitle.setTextAppearance(context, android.R.style.TextAppearance_DeviceDefault_Widget_ActionBar_Title);
		tvTitle.setTextColor(Color.WHITE);
		tvTitle.setSingleLine(true);
		addView(tvTitle, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
		
		icsSpIndex = new IcsSpinner(context, null);
		icsSpIndex.setAdapter(adapter);
		icsSpIndex.setPadding(2, 0, 20, 5);
		addView(icsSpIndex, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

	}

	/**
	 * Instantiates a new ab exam title.
	 *
	 * @param context the context
	 * @param attrs the attrs
	 */
	public AbExamTitle(Context context, AttributeSet attrs) {
		super(context, attrs);
		// TODO Auto-generated constructor stub
	}

	/**
	 * Instantiates a new ab exam title.
	 *
	 * @param context the context
	 * @param attrs the attrs
	 * @param defStyle the def style
	 */
	@SuppressLint("NewApi")
	public AbExamTitle(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	/**
	 * Gets the title.
	 *
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * Sets the title.
	 *
	 * @param title the new title
	 */
	public void setTitle(String title) {
		tvTitle.setText(title);
		this.title = title;
	}
	
	/**
	 * Sets the on spinner index selected listener.
	 *
	 * @param onItemSelectedListener the new on spinner index selected listener
	 */
	public void setOnSpinnerIndexSelectedListener(OnItemSelectedListener onItemSelectedListener){
		icsSpIndex.setOnItemSelectedListener(onItemSelectedListener);
	}
	
	/**
	 * Select.
	 *
	 * @param index the index
	 */
	public void select(int index){
		icsSpIndex.setSelection(index);
	}

}
